package com.prs.crm.service.doc.impl;

import java.util.Collection;
import java.util.Date;

import com.prs.crm.context.ToolKits;
import com.prs.crm.dao.doc.IssueKnowledgeDao;
import com.prs.crm.domain.doc.IssueKnowledge;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.domain.oa.Knowledge;
import com.prs.crm.service.doc.IssueKnowledgeService;
import com.prs.crm.service.hr.PersonService;
import com.prs.crm.service.impl.BaseServiceImpl;
import com.prs.crm.service.oa.KnowledgeService;

public class IssueKnowledgeServiceImpl extends BaseServiceImpl<IssueKnowledge,IssueKnowledgeDao> implements IssueKnowledgeService{
	private KnowledgeService knowledgeService;
	private PersonService personService;
	
	@Override
	public void submitIssueKnowledge(Date issueStartTime, Date issueEndTime,
			String issueDocIds, String receivePersons) {
		// TODO Auto-generated method stub
		Collection<Knowledge> knowledges = this.getKnowledgeService().getKnowledgeByIds(ToolKits.convertStringAryToIntAry(issueDocIds, ","));
		Collection<Person> persons = this.getPersonService().findPersons(ToolKits.convertStringAryToIntAry(receivePersons.split(",")));
		
		for(Person person : persons) {
			for(Knowledge knowledge : knowledges) {
				IssueKnowledge issue = new IssueKnowledge();
				issue.setKnowledge(knowledge);
				issue.setReceivePerson(person);
				issue.setStartTime(issueStartTime);
				issue.setEndTime(issueEndTime);
				
				this.getDao().save(issue);
			}
		}
	}
	public void setKnowledgeService(KnowledgeService knowledgeService) {
		this.knowledgeService = knowledgeService;
	}
	public KnowledgeService getKnowledgeService() {
		return knowledgeService;
	}
	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}
	public PersonService getPersonService() {
		return personService;
	}
	@Override
	public Collection<IssueKnowledge> getValidIssueKnowledge(Person person) {
		// TODO Auto-generated method stub
		return this.getDao().getValidIssueKnowledge(person);
	}

}
